#ifndef _BBEVENTDISPATCHER_H_
#define _BBEVENTDISPATCHER_H_

#include "BBObject.h"

class BBEvent;

/*
	BBHandler
*/
class BBHandler : public BBObject
{
public:
	static BBHandler* create(BBEvent* evt,LP_EVENT_CALLBACK callBack);
public:
	BBHandler(BBEvent* evt,LP_EVENT_CALLBACK callBack);
	~BBHandler(void);
	void registerEvent(BBEvent* evt);
	void registerEventCallBack(LP_EVENT_CALLBACK callBack);
	void Invoke();
	BBEvent* getEvent() { return m_pEvent;}
	virtual void Release();
protected:
	BBEvent* m_pEvent;
	LP_EVENT_CALLBACK m_pEventCallBack;
};


class IEventDispatch
{
 	virtual void addEventListener(int evtType,BBHandler* hander,int priority= 0,bool useCapture = false) = 0;
 	virtual void removeEventListener(int evtTpe,BBHandler* hander,bool useCapture = false) = 0;
	virtual void dispatchEvent(BBEvent* event) = 0;
};


class BBEventDispatcher : public BBObject,public IEventDispatch
{
public:
	BBEventDispatcher(void);
	virtual ~BBEventDispatcher(void);

	virtual void addEventListener(int evtType,BBHandler* hander,int priority= 0,bool useCapture = false);
	virtual void removeEventListener(int evtTpe,BBHandler* hander);
	virtual void dispatchEvent(BBEvent* event);
	virtual void Release();
};


#endif //_BBEVENTDISPATCHER_H_